#include <cstdio>
#include <cstring>
using namespace std;
#define DEBUG

inline int read()
{
    int c=getchar(), f=1, x=0;
    if(c=='-') f*=-1, x=getchar();
    while(c<'0'&&'9'<c) c=getchar();
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    return f*x;
}
inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}

int n, k;

void init()
{
    scanf("%d %d", &n, &k);

}

void solve()
{
    init();
    int x, y, len; char op[101];
    while(k--)
    {
        scanf("%d %d", &x, &y);
        scanf("%s", op);
        len=strlen(op);
        for(int i=0; i<len; i++)
        {
            if(op[i]=='f')
                y = y==n?n:y+1;
            else if(op[i]=='b')
                y = y==1?1:y-1;
            else if(op[i]=='l')
                x = x==1?1:x-1;
            else if(op[i]=='r')
                x = x==n?n:x+1;
            // printf("debug:%c %d %d\n", op[i], x, y);
        }
        printf("%d %d\n", x, y);
    }
}

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--)
    {
        solve();
    }
    return 0;
}